import * as _lodash from "lodash";
interface stateType {
    assemblyList: any; // 装配的数据
    curSelectedAssembly: any; // 选中当前组件属性数据
    delAssembly: any; // 要删除的项
    delIndex: number; // 要删除的项的下标
}
export type Action = { type: string; payload: stateType}


const reducer = (state: stateType, action: Action) => {
    
    switch (action.type) {
        case "SET_ASSEMBLY_LIST":  // 设置组件列表
            state.assemblyList = action.payload.assemblyList;
            break;
        case "SET_SELECT_ASSEMBLY":  //设置选中的组件
            state.curSelectedAssembly = action.payload.curSelectedAssembly;
            break;
        case "DEL_ASSEMBLY":  //设置选中的组件
            state.delIndex = action.payload.delIndex;
            // eslint-disable-next-line no-case-declarations
            const list = _lodash.cloneDeep(state.assemblyList);
            list.splice(state.delIndex, 1);
            state.assemblyList = list;
            console.log(state.assemblyList);
            break;
        default: 
            break;
    }
    return {...state};
};

export default reducer;